/*****************************************************************************
 *
 * MODULE:              Configuration for the UDP Home Sensor Demo
 *
 * REVISION:            $Revision: 12289 $
 *
 * DATED:               $Date: 2009-04-22 15:18:41 +0100 (Wed, 22 Apr 2009) $
 *
 * DESCRIPTION:
 * Configuration settings for demo system
 *
 *
 ****************************************************************************/


#ifndef  DEMO_CONFIG_INCLUDED
#define  DEMO_CONFIG_INCLUDED

#if defined __cplusplus
extern "C"
{
#endif

/****************************************************************************/
/***        Include Files                                                 ***/
/****************************************************************************/

#include "jendefs.h"

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/

/* Special bytes, keep in sync with Java classes ! */
#define MESSAGE_FIELD_SEPARATOR         ';'
#define MESSAGE_WRAPPER                 '$'
#define MESSAGE_PROTOCOL_VERSION_1      'M'
#define MESSAGE_PROTOCOL_VERSION_2      '1'

#define DEVICE_FIELD_SEPARATOR          '!'
#define DEVICE_PROTOCOL_VERSION_1       'O'
#define DEVICE_PROTOCOL_VERSION_2       '1'
#define DEVICE_HELLO_PREFIX             'H'
#define DEVICE_PROBE_PREFIX             'P'
#define DEVICE_BYE_PREFIX               'B'
#define DEVICE_GETMETADATA_PREFIX       'G'
#define DEVICE_METADATA_PREFIX          'M'
#define DEVICE_EVENT_PREFIX             'E'

#define DEVICE_EVENT_KV_SEPARATOR       '|'
#define DEVICE_EVENT_FIELD_SEPARATOR    ';'

#define DEVICE_METADATA_KV_SEPARATOR    '|'
#define DEVICE_METADATA_FIELD_SEPARATOR ';'

/* The port number for both sending and receiving the data */
//#define	PC_UDP_PORT 0xf0b1
#define	PC_UDP_PORT 0xf0b1
#define DISCOVERY_PORT 0xf0b2

/* The address of the PC to send the data to (fd04:0bd3:80e8:0001::2)	 */
#define PC_ADDR_0 0xfd040bd3
#define PC_ADDR_1 0x80e80001
#define PC_ADDR_2 0x0
#define PC_ADDR_3 0x02
//#define PC_ADDR_0 0x FD04 0BD3 U
//#define PC_ADDR_1 0x 80E8 0002 U
//#define PC_ADDR_2 0x 0215 8D00 U
//#define PC_ADDR_3 0x 0008 61F2 U

/* PAN ID on which demo operates */
#define PAN_ID 0x1112

/* Address prefix in IPv6 domain on which demo operates */
#define ADDRESS_PREFIX 0xfd040bd380e80002ULL

#define NETWORK_APPLICATION_ID 0x11121112

/* Channels available  */
#define CHANNEL_BITMAP               0x7fff800
/* #define CHANNEL_FIXED                       18
#define CHANNEL_BITMAP               (1 << CHANNEL_FIXED) */
/* wnconfig -c 18 -p 0x1112 -n 0x11121112 -prefix 0xfd040bd380e80002 */

/* Define this if using a high power module, otherwise leave commented out */
/* #define HIGH_POWER_MODULE */

/*
 *  The size of the data that we want to send.
 *  If this is larger than the useful data, the payload will be padded.
 */
#define TRANSMIT_PAYLOAD_SIZE 200


/*
 * The size of data that we are interested in receiving.
 * This must be larger than the payload sent from the PC.
 */
#define RECEIVE_PAYLOAD_SIZE 150

/*
 * The Maximum Transmission Unit (MTU) is the largest IPv6 packet that the system can handle.
 * We should configure this to be as small as possible while still allowing us enough space
 * for the largest payload that we will send or receive.
 * The MTU is the size of the data + the UDP header (8) + the IP header (40).
 * JIP / 6LowPAN has a maximum MTU of 1280 and a minimum of 256.
 *
 */
#if (TRANSMIT_PAYLOAD_SIZE+48+4)<256
    #define MAX_MTU 256
 #else
    #define MAX_MTU (TRANSMIT_PAYLOAD_SIZE+48+4)
#endif

/*
 *  The packet buffers are allocated from a single block of statically allocated memory.
 *  Each packet buffer contains an internal structure of about 300 bytes and the MTU without the header.
 *  The smaller the MTU, the smaller the memory needed or the more buffers we can have.
 */
#define PACKET_BUFFER_SIZE (10 * (MAX_MTU - 48 + 300))

/*
 * End devices go to sleep to save energy.
 * SLEEP_MILLISECS is the time for which the devices sleep
 * If this is set too large, it is possible that messages from the PC will get lost.
 * The LEDs can only flash in multiples of SLEEP_MILLISECS.
 *
 * A message is not necessarily sent every time the device wakes up.
 * MESSAGE_DIVIDER is how many wake times to leave before sending the next message.
 */

#define SLEEP_MILLISECS 50
#define MESSAGE_DIVIDER 20
/*
 * An interrupt driven clock is used to drive the LED flashing when waiting
 * for the network.  The router also uses the clock to drive the LED flashing
 * when running and the pause time.
 *
 * The timer has a 16Mhz clock.  The pre-scaler is set to 16 so the clock is
 * divided by 2^16.
 * Flash period of 1  in 1/10 sec units means on for 1/20 and off for 1/20 sec.
 * LED flash clock period is 1/20 second at 16Mhz / (2^16).
 */

#define INT_TIMER_FREQ_HZ 20
#define FLASH_CLOCK_PERIOD  ((16000000 / (1 << 16)) / INT_TIMER_FREQ_HZ)
/*
 * Routers don't sleep as they need to be able to receive a
 * message at any time, in case an end device is attempting to transmit a message.
 * The routers use the timer that controls the LED flashing to time the pause state.
 */

#define PAUSE_TIMER_TICKS (INT_TIMER_FREQ_HZ*15)

#if defined __cplusplus
}
#endif

#endif  /* DEMO_CONFIG_INCLUDED */

/****************************************************************************/
/***        END OF FILE                                                   ***/
/****************************************************************************/
